<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
      :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="服务标题" prop="title">
              <el-input v-model="queryParams.title" placeholder="请输入服务标题" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="服务分类" prop="categoryId">
              <el-select v-model="queryParams.categoryId" placeholder="请选择服务分类" clearable>
                <el-option v-for="dict in xqfl" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="服务地区" prop="location">
              <el-input v-model="queryParams.location" placeholder="请输入服务地区" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="联系姓名" prop="contactName">
              <el-input v-model="queryParams.contactName" placeholder="请输入联系人姓名" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input v-model="queryParams.contactPhone" placeholder="请输入联系电话" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
                <el-option v-for="dict in xqzt" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd"
              v-hasPermi="['system:services:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()"
              v-hasPermi="['system:services:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
              v-hasPermi="['system:services:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport"
              v-hasPermi="['system:services:export']">导出</el-button>
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button type="success" plain icon="Checked" :disabled="multiple" @click="handleBatchAudit()"
              v-hasPermi="['system:services:audit']">
              批量审核
            </el-button>
          </el-col> -->
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="servicesList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="服务ID" align="center" prop="id" v-if="false" />
        <el-table-column label="服务标题" align="center" prop="title" show-overflow-tooltip />
        <el-table-column label="服务分类" align="center" prop="categoryId">
          <template #default="scope">
            <dict-tag :options="xqfl" :value="scope.row.categoryId" />
          </template>
        </el-table-column>
        <el-table-column label="服务简介" align="center" prop="intro" show-overflow-tooltip />
        <el-table-column label="服务价格" align="center" prop="price">
          <template #default="scope">
            <el-tag v-if="scope.row.priceNegotiable === 1">面议</el-tag>
            <el-tag v-else>￥{{ scope.row.price }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="服务地区" align="center" prop="location" />
        <el-table-column label="联系人姓名" align="center" prop="contactName" />
        <el-table-column label="联系电话" align="center" prop="contactPhone" />
        <el-table-column label="状态" align="center" prop="status">
          <template #default="scope">
            <dict-tag :options="xqzt" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="浏览次数" align="center" prop="viewCount" />
        <el-table-column label="咨询次数" align="center" prop="inquiryCount" />
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
          <template #default="scope">
            <el-tooltip content="查看详情" placement="top">
              <el-button link type="primary" icon="View" @click="handleDetail(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="审核" placement="top" v-if="scope.row.status === 1">
              <el-button link type="warning" icon="CircleCheck" @click="handleAudit(scope.row)"
                v-hasPermi="['system:services:audit']"></el-button>
            </el-tooltip>
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['system:services:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                v-hasPermi="['system:services:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改服务信息对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="900px" append-to-body class="service-dialog">
      <el-form ref="servicesFormRef" :model="form" :rules="rules" label-width="110px" class="service-form">
        <!-- 基本信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Document />
            </el-icon>
            <span class="section-title">基本信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="服务标题" prop="title">
                <el-input v-model="form.title" placeholder="请输入服务标题" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="服务分类" prop="categoryId">
                <el-select v-model="form.categoryId" placeholder="请选择服务分类" clearable style="width: 100%">
                  <el-option v-for="dict in xqfl" :key="dict.value" :label="dict.label"
                    :value="parseInt(dict.value)"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="服务简介" prop="intro">
                <el-input v-model="form.intro" type="textarea" :rows="2" placeholder="请输入服务简介（一句话简介），简要描述您的服务"
                  clearable />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="服务详细内容">
                <editor v-model="form.content" :min-height="180" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 价格信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Money />
            </el-icon>
            <span class="section-title">价格信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="价格是否面议" prop="priceNegotiable">
                <el-radio-group v-model="form.priceNegotiable" @change="handlePriceNegotiableChange">
                  <el-radio-button label="否" :value="0">
                    <span>否 <span style="color: #0055ff; font-size: 12px">（需填写具体价格）</span></span>
                  </el-radio-button>
                  <el-radio-button label="是" :value="1">
                    <span>是 <span style="color: #0056ff; font-size: 12px">（面议）</span></span>
                  </el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="form.priceNegotiable === 0">
              <el-form-item label="服务价格" prop="price">
                <el-input-number v-model="form.price" :min="0" :precision="2" placeholder="请输入服务价格"
                  controls-position="right" style="width: 100%" />
                <div class="form-tip">
                  <el-icon>
                    <InfoFilled />
                  </el-icon>
                  <span>请输入具体的服务价格（单位：元）</span>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 地区信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Location />
            </el-icon>
            <span class="section-title">地区信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="服务地区" prop="location">
                <el-input v-model="form.location" placeholder="如：广东省深圳市" clearable />
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 联系信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <User />
            </el-icon>
            <span class="section-title">联系信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="联系人姓名" prop="contactName">
                <el-input v-model="form.contactName" placeholder="请输入联系人姓名" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="contactPhone">
                <el-input v-model="form.contactPhone" placeholder="请输入手机号码" clearable maxlength="11" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 统计信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <DataAnalysis />
            </el-icon>
            <span class="section-title">统计信息</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="浏览次数" prop="viewCount">
                <el-input-number v-model="form.viewCount" :min="0" placeholder="浏览次数" controls-position="right"
                  style="width: 100%" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="咨询次数" prop="inquiryCount">
                <el-input-number v-model="form.inquiryCount" :min="0" placeholder="咨询次数" controls-position="right"
                  style="width: 100%" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 状态信息 -->
        <div class="form-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Setting />
            </el-icon>
            <span class="section-title">状态设置</span>
          </div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="状态" prop="status">
                <el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
                  <el-option v-for="dict in xqzt" :key="dict.value" :label="dict.label"
                    :value="parseInt(dict.value)"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel" size="large">
            <el-icon>
              <Close />
            </el-icon>
            <span>取 消</span>
          </el-button>
          <el-button :loading="buttonLoading" type="primary" @click="submitForm" size="large">
            <el-icon>
              <Check />
            </el-icon>
            <span>确 定</span>
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 服务详情对话框 -->
    <el-dialog title="服务详情" v-model="detailDialog.visible" width="800px" append-to-body class="service-detail-dialog">
      <div v-if="detailData" class="service-detail">
        <!-- 基本信息 -->
        <div class="detail-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Document />
            </el-icon>
            <span class="section-title">基本信息</span>
          </div>
          <div class="detail-content">
            <div class="detail-row">
              <span class="label">服务标题：</span>
              <span class="value">{{ detailData.title }}</span>
            </div>
            <div class="detail-row">
              <span class="label">服务分类：</span>
              <span class="value">
                <dict-tag :options="xqfl" :value="detailData.categoryId" />
              </span>
            </div>
            <div class="detail-row">
              <span class="label">服务简介：</span>
              <span class="value">{{ detailData.intro }}</span>
            </div>
            <div class="detail-row full-width">
              <span class="label">详细内容：</span>
              <div class="value content-value" v-html="detailData.content"></div>
            </div>
          </div>
        </div>

        <!-- 价格信息 -->
        <div class="detail-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Money />
            </el-icon>
            <span class="section-title">价格信息</span>
          </div>
          <div class="detail-content">
            <div class="detail-row">
              <span class="label">价格类型：</span>
              <span class="value">
                <el-tag v-if="detailData.priceNegotiable === 1" type="warning">面议</el-tag>
                <el-tag v-else type="success">固定价格</el-tag>
              </span>
            </div>
            <div class="detail-row" v-if="detailData.priceNegotiable === 0">
              <span class="label">服务价格：</span>
              <span class="value price-value">￥{{ detailData.price }}</span>
            </div>
          </div>
        </div>

        <!-- 地区信息 -->
        <div class="detail-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <Location />
            </el-icon>
            <span class="section-title">地区信息</span>
          </div>
          <div class="detail-content">
            <div class="detail-row">
              <span class="label">服务地区：</span>
              <span class="value">{{ detailData.location }}</span>
            </div>
          </div>
        </div>

        <!-- 联系信息 -->
        <div class="detail-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <User />
            </el-icon>
            <span class="section-title">联系信息</span>
          </div>
          <div class="detail-content">
            <div class="detail-row">
              <span class="label">联系人：</span>
              <span class="value">{{ detailData.contactName }}</span>
            </div>
            <div class="detail-row">
              <span class="label">联系电话：</span>
              <span class="value contact-phone">{{ detailData.contactPhone }}</span>
            </div>
          </div>
        </div>

        <!-- 统计信息 -->
        <div class="detail-section">
          <div class="section-header">
            <el-icon class="section-icon">
              <DataAnalysis />
            </el-icon>
            <span class="section-title">统计信息</span>
          </div>
          <div class="detail-content">
            <div class="detail-row">
              <span class="label">浏览次数：</span>
              <span class="value">{{ detailData.viewCount || 0 }}</span>
            </div>
            <div class="detail-row">
              <span class="label">咨询次数：</span>
              <span class="value">{{ detailData.inquiryCount || 0 }}</span>
            </div>
            <div class="detail-row">
              <span class="label">状态：</span>
              <span class="value">
                <dict-tag :options="xqzt" :value="detailData.status" />
              </span>
            </div>
            <div class="detail-row">
              <span class="label">创建时间：</span>
              <span class="value">{{ parseTime(detailData.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </div>
          </div>
        </div>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="detailDialog.visible = false" size="large">
            <el-icon>
              <Close />
            </el-icon>
            <span>关 闭</span>
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 审核对话框 -->
    <el-dialog title="审核服务" v-model="auditDialog.visible" width="600px" append-to-body class="audit-dialog">
      <div v-if="auditData" class="audit-content">
        <!-- 服务基本信息 -->
        <div class="audit-info-section">
          <div class="info-row">
            <span class="label">服务标题：</span>
            <span class="value">{{ auditData.title }}</span>
          </div>
          <div class="info-row">
            <span class="label">服务分类：</span>
            <span class="value">
              <dict-tag :options="xqfl" :value="auditData.categoryId" />
            </span>
          </div>
          <div class="info-row">
            <span class="label">服务地区：</span>
            <span class="value">{{ auditData.location }}</span>
          </div>
          <div class="info-row">
            <span class="label">联系人：</span>
            <span class="value">{{ auditData.contactName }} / {{ auditData.contactPhone }}</span>
          </div>
        </div>

        <!-- 审核表单 -->
        <el-form ref="auditFormRef" :model="auditForm" :rules="auditRules" label-width="100px" class="audit-form">
          <el-form-item label="审核结果" prop="status">
            <el-radio-group v-model="auditForm.status">
              <el-radio :value="0" border>
                <el-icon color="#67c23a">
                  <CircleCheck />
                </el-icon>
                <span>审核通过</span>
              </el-radio>
              <el-radio :value="2" border>
                <el-icon color="#f56c6c">
                  <CircleClose />
                </el-icon>
                <span>审核驳回</span>
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="驳回原因" prop="reason" v-if="auditForm.status === 2">
            <el-input v-model="auditForm.reason" type="textarea" :rows="4" placeholder="请输入驳回原因" maxlength="200"
              show-word-limit />
          </el-form-item>
        </el-form>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="auditDialog.visible = false" size="large">
            <el-icon>
              <Close />
            </el-icon>
            <span>取 消</span>
          </el-button>
          <el-button :loading="auditLoading" type="primary" @click="submitAudit" size="large">
            <el-icon>
              <Check />
            </el-icon>
            <span>提交审核</span>
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Services" lang="ts">
import { listServices, getServices, delServices, addServices, updateServices, auditServices } from '@/api/business/services';
import { ServicesVO, ServicesQuery, ServicesForm, AuditBo } from '@/api/business/services/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { xqfl, xqzt } = toRefs<any>(proxy?.useDict('xqfl', 'xqzt'));

const servicesList = ref<ServicesVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const servicesFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

// 详情对话框
const detailDialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

// 详情数据
const detailData = ref<ServicesVO | null>(null);

// 审核对话框
const auditDialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

// 审核数据
const auditData = ref<ServicesVO | null>(null);
const auditLoading = ref(false);
const auditFormRef = ref<ElFormInstance>();
const currentAuditIds = ref<Array<string | number>>([]); // 用于存储当前需要审核的ID，可以是单个或批量

// 审核表单
const auditForm = reactive<AuditBo>({
  ids: '',
  status: 0,
  reason: ''
});

// 审核表单验证规则
const auditRules = {
  status: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
  reason: [
    {
      validator: (rule: any, value: string, callback: any) => {
        if (auditForm.status === 2 && !value) {
          callback(new Error('请输入驳回原因'));
        } else {
          callback();
        }
      },
      trigger: 'blur'
    }
  ]
};

const initFormData: ServicesForm = {
  id: undefined,
  title: undefined,
  categoryId: undefined,
  intro: undefined,
  content: undefined,
  price: undefined,
  priceNegotiable: undefined,
  location: undefined,
  contactName: undefined,
  contactPhone: undefined,
  status: undefined,
  viewCount: undefined,
  inquiryCount: undefined
};
const data = reactive<PageData<ServicesForm, ServicesQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    title: undefined,
    categoryId: undefined,
    priceNegotiable: undefined,
    location: undefined,
    contactName: undefined,
    contactPhone: undefined,
    status: undefined,
    params: {}
  },
  rules: {
    id: [{ required: true, message: '服务ID不能为空', trigger: 'blur' }],
    title: [{ required: true, message: '服务标题不能为空', trigger: 'blur' }],
    categoryId: [{ required: true, message: '服务分类不能为空', trigger: 'change' }],
    intro: [{ required: true, message: '服务简介不能为空', trigger: 'blur' }],
    content: [{ required: true, message: '服务详细内容不能为空', trigger: 'blur' }],
    priceNegotiable: [{ required: true, message: '价格是否面议不能为空', trigger: 'blur' }],
    location: [{ required: true, message: '服务地区不能为空', trigger: 'blur' }],
    contactName: [{ required: true, message: '联系人姓名不能为空', trigger: 'blur' }],
    contactPhone: [{ required: true, message: '联系电话不能为空', trigger: 'blur' }],
    status: [{ required: true, message: '状态：0-已发布，1-待审核，2-已下架不能为空', trigger: 'change' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询服务信息列表 */
const getList = async () => {
  loading.value = true;
  const res = await listServices(queryParams.value);
  servicesList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
};

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  servicesFormRef.value?.resetFields();
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: ServicesVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 价格是否面议变更处理 */
const handlePriceNegotiableChange = (value: number) => {
  if (value === 1) {
    // 选择"是"时，清空价格输入框
    form.value.price = undefined;
  }
};

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加服务信息';
  // 设置默认值
  form.value.priceNegotiable = 0;
  form.value.status = 0; // 默认状态为已发布
};

/** 修改按钮操作 */
const handleUpdate = async (row?: ServicesVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getServices(_id);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = '修改服务信息';
};

/** 提交按钮 */
const submitForm = () => {
  servicesFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateServices(form.value).finally(() => (buttonLoading.value = false));
      } else {
        await addServices(form.value).finally(() => (buttonLoading.value = false));
      }
      proxy?.$modal.msgSuccess('操作成功');
      dialog.visible = false;
      await getList();
    }
  });
};

/** 删除按钮操作 */
const handleDelete = async (row?: ServicesVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除服务信息编号为"' + _ids + '"的数据项？').finally(() => (loading.value = false));
  await delServices(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

/** 查看详情操作 */
const handleDetail = async (row: ServicesVO) => {
  const res = await getServices(row.id);
  detailData.value = res.data;
  detailDialog.visible = true;
};

/** 审核按钮操作 */
const handleAudit = async (row: ServicesVO) => {
  const res = await getServices(row.id);
  auditData.value = res.data;
  currentAuditIds.value = [row.id]; // 单个审核

  // 重置审核表单
  auditForm.status = 0;
  auditForm.reason = '';
  auditFormRef.value?.clearValidate();

  auditDialog.visible = true;
};

/** 批量审核按钮操作 */
const handleBatchAudit = () => {
  auditData.value = null; // 批量审核不需要显示单个数据详情
  currentAuditIds.value = ids.value; // 批量审核

  // 重置审核表单
  auditForm.status = 0;
  auditForm.reason = '';
  auditFormRef.value?.clearValidate();

  auditDialog.title = '批量审核服务';
  auditDialog.visible = true;
};

/** 提交审核 */
const submitAudit = () => {
  auditFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      auditLoading.value = true;
      try {
        const auditRequest: AuditBo = {
          ids: currentAuditIds.value.join(','),
          status: auditForm.status,
          reason: auditForm.reason
        };
        await auditServices(auditRequest);
        const statusText = auditForm.status === 0 ? '通过' : '驳回';
        proxy?.$modal.msgSuccess(`审核${statusText}成功`);
        auditDialog.visible = false;
        await getList();
      } catch (error) {
        console.error('审核失败:', error);
      } finally {
        auditLoading.value = false;
      }
    }
  });
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'system/services/export',
    {
      ...queryParams.value
    },
    `services_${new Date().getTime()}.xlsx`
  );
};

onMounted(() => {
  getList();
});
</script>

<style scoped lang="scss">
// 对话框样式
.service-dialog {
  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    margin: 0;

    .el-dialog__title {
      color: #fff;
      font-size: 18px;
      font-weight: 600;
    }

    .el-dialog__close {
      color: #fff;
      font-size: 20px;

      &:hover {
        color: #f0f0f0;
      }
    }
  }

  :deep(.el-dialog__body) {
    padding: 25px 30px;
    max-height: 70vh;
    overflow-y: auto;
    background-color: #f5f7fa;
  }

  :deep(.el-dialog__footer) {
    padding: 15px 30px;
    background-color: #fff;
    border-top: 1px solid #e4e7ed;
  }
}

// 表单整体样式
.service-form {

  // 表单区块
  .form-section {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    &:last-child {
      margin-bottom: 0;
    }
  }

  // 区块标题
  .section-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f2f5;

    .section-icon {
      font-size: 20px;
      color: #409eff;
      margin-right: 10px;
    }

    .section-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;
      letter-spacing: 0.5px;
    }
  }

  // 提示信息样式
  .form-tip {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 12px;
    background: #ecf5ff;
    border-radius: 6px;
    font-size: 13px;
    color: #409eff;

    .el-icon {
      font-size: 14px;
    }
  }

  // 表单项样式
  :deep(.el-form-item) {
    margin-bottom: 20px;

    .el-form-item__label {
      font-weight: 500;
      color: #606266;
    }

    .el-input__inner,
    .el-textarea__inner {
      border-radius: 6px;
      transition: all 0.3s ease;

      &:focus {
        border-color: #409eff;
        box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.1);
      }
    }

    .el-select {
      .el-input__inner {
        border-radius: 6px;
      }
    }
  }

  // 数字输入框样式
  :deep(.el-input-number) {
    width: 100%;

    .el-input__inner {
      text-align: left;
      border-radius: 6px;
    }
  }

  // 单选框组样式
  :deep(.el-radio-group) {
    width: 100%;

    .el-radio-button {
      flex: 1;

      .el-radio-button__inner {
        border-radius: 6px;
        border: 1px solid #dcdfe6;
        background: #fff;
        color: #606266;
        transition: all 0.3s ease;

        &:hover {
          color: #409eff;
          border-color: #409eff;
        }
      }

      &.is-active .el-radio-button__inner {
        background: #409eff;
        border-color: #409eff;
        color: #fff;
      }
    }
  }
}

// 底部按钮样式
.dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;

  .el-button {
    min-width: 120px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;

    .el-icon {
      margin-right: 6px;
    }

    &.el-button--primary {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border: none;

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
      }

      &:active {
        transform: translateY(0);
      }
    }

    &:not(.el-button--primary) {
      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      }
    }
  }
}

// 滚动条样式
:deep(.el-dialog__body)::-webkit-scrollbar {
  width: 6px;
}

:deep(.el-dialog__body)::-webkit-scrollbar-thumb {
  background-color: #dcdfe6;
  border-radius: 3px;

  &:hover {
    background-color: #c0c4cc;
  }
}

:deep(.el-dialog__body)::-webkit-scrollbar-track {
  background-color: transparent;
}

// ==================== 详情对话框样式 ====================
.service-detail-dialog {
  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    padding: 20px;
    margin: 0;

    .el-dialog__title {
      color: #fff;
      font-size: 18px;
      font-weight: 600;
    }

    .el-dialog__close {
      color: #fff;
      font-size: 20px;

      &:hover {
        color: #f0f0f0;
      }
    }
  }

  :deep(.el-dialog__body) {
    padding: 25px 30px;
    max-height: 70vh;
    overflow-y: auto;
    background-color: #f8fafc;
  }

  :deep(.el-dialog__footer) {
    padding: 15px 30px;
    background-color: #fff;
    border-top: 1px solid #e4e7ed;
  }
}

// 详情内容样式
.service-detail {
  .detail-section {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    &:last-child {
      margin-bottom: 0;
    }
  }

  .section-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f2f5;

    .section-icon {
      font-size: 20px;
      color: #22c55e;
      margin-right: 10px;
    }

    .section-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;
      letter-spacing: 0.5px;
    }
  }

  .detail-content {
    .detail-row {
      display: flex;
      margin-bottom: 16px;
      align-items: flex-start;

      &.full-width {
        flex-direction: column;
        align-items: stretch;
      }

      &:last-child {
        margin-bottom: 0;
      }

      .label {
        font-weight: 600;
        color: #606266;
        min-width: 120px;
        margin-right: 12px;
        flex-shrink: 0;
      }

      .value {
        color: #303133;
        flex: 1;
        word-break: break-all;

        &.price-value {
          font-size: 18px;
          font-weight: 700;
          color: #22c55e;
        }

        &.contact-phone {
          font-family: 'Courier New', monospace;
          font-weight: 600;
          color: #409eff;
        }

        &.content-value {
          background: #f8fafc;
          padding: 16px;
          border-radius: 8px;
          border: 1px solid #e5e7eb;
          margin-top: 8px;
          line-height: 1.6;

          :deep(p) {
            margin: 0 0 12px 0;

            &:last-child {
              margin-bottom: 0;
            }
          }

          :deep(img) {
            max-width: 100%;
            height: auto;
            border-radius: 6px;
            margin: 8px 0;
          }
        }
      }
    }
  }
}

// ==================== 审核对话框样式 ====================
.audit-dialog {
  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    padding: 20px;
    margin: 0;

    .el-dialog__title {
      color: #fff;
      font-size: 18px;
      font-weight: 600;
    }

    .el-dialog__close {
      color: #fff;
      font-size: 20px;

      &:hover {
        color: #f0f0f0;
      }
    }
  }

  :deep(.el-dialog__body) {
    padding: 25px 30px;
    background-color: #f5f7fa;
  }
}

.audit-content {
  .audit-info-section {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

    .info-row {
      display: flex;
      align-items: center;
      padding: 10px 0;
      border-bottom: 1px solid #f0f2f5;

      &:last-child {
        border-bottom: none;
      }

      .label {
        font-weight: 600;
        color: #606266;
        min-width: 100px;
        flex-shrink: 0;
      }

      .value {
        color: #303133;
        flex: 1;
      }
    }
  }

  .audit-form {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

    :deep(.el-radio-group) {
      display: flex;
      gap: 15px;

      .el-radio.is-bordered {
        padding: 12px 20px;
        border-radius: 8px;
        margin-right: 0;
        transition: all 0.3s ease;

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        &.is-checked {
          border-width: 2px;
        }

        .el-radio__label {
          display: flex;
          align-items: center;
          gap: 6px;
          font-weight: 500;
        }
      }
    }

    :deep(.el-textarea) {
      .el-textarea__inner {
        border-radius: 8px;
        resize: none;
      }
    }
  }
}
</style>
